﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace SpaceNeedle.x6473.WindowsPhone.Utils
{
    public class ImageUtils
    {
        public static string ConvertBitmapImageToBase64String(BitmapImage bitmap)
        {
            try
            {
                byte[] bytes = null;

                using (MemoryStream ms = new MemoryStream())
                {
                    WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap);
                    writeableBitmap.SaveJpeg(ms, 46, 38, 0, 100);
                    bytes = ms.ToArray();

                }

                return Convert.ToBase64String(bytes);
            }
            catch { }

            return string.Empty;
        }
    }
}
